package com.qiang.test07;

public class Cooker implements Runnable {
    @Override
    public void run() {

        while (true) {
            synchronized (Desk.ob) {
                if (Desk.num <= 0) {
                    break;
                } else {
                    if (Desk.flag == false) {
                        //有
                        System.out.println("厨师正在生产汉堡包");
                        Desk.flag = true;
                        Desk.ob.notifyAll();
                        Desk.num--;
                    } else {
                        //没有就等待
                        //使用什么对象当做锁,那么就必须用这个对象去调用等待和唤醒的方法.
                        try {
                            Desk.ob.wait();
                            Desk.ob.notifyAll();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }
    }
}
